package de.bht.cge.flightsim.game;

import java.io.File;

import de.bht.cge.flightsim.util.Helper;
import de.bht.cge.flightsim.util.Settings;
import de.bht.jvr.collada14.loader.ColladaLoader;
import de.bht.jvr.core.Finder;
import de.bht.jvr.core.Geometry;
import de.bht.jvr.core.SceneNode;
import de.bht.jvr.core.ShaderMaterial;
import de.bht.jvr.core.ShapeNode;
import de.bht.jvr.core.Transform;
import de.bht.jvr.math.Vector3;

public class Plane extends Base
{	
    
    private boolean firstPerson = false;
    private float rotZ = 0.0f;
    
	
	public Plane(float scale, SceneNode node, boolean firstPerson)
	{
	    super(scale,"Plane");
		this.setPosition(node.getTransform().getMatrix().translation().add(new Vector3(0,90,0)));	
		this.setFirstPerson(firstPerson);
		
		try
		{
			this.Build();
		}
		catch (Exception e)
		{			
			e.printStackTrace();
		}
		
	}
	
	
	@Override
	public void Build() throws Exception
	{
		super.Build();		
				
		SceneNode node = ColladaLoader.load(new File("meshes/plane002.dae"));
		ShaderMaterial mat = ShaderMaterial.makePhongShaderMaterial();
		Finder.find(node, ShapeNode.class, null).setMaterial(mat);	   
		node.setTransform(Transform.rotateXDeg(90).mul(Transform.rotateYDeg(180)).mul(Transform.scale(this.getScale())));
		this.setTransform(Transform.translate(this.getPosition()));
		
		this.addChildNode(node);
	}
	
	public void update(Vector3 cam) 
	{
	    if(this.isFirstPerson())
	    {
	        this.setTransform(Transform.translate(cam));
	    }
	    else
	    {
	        this.setTransform(Transform.translate(cam.add(Settings.PlaneCameraDistance)));
	    }
	    
	}
	
	public void rotate(float delta)
	{
	    this.setTransform(Transform.rotateZ(this.rotZ));
	}
	

    public boolean isFirstPerson()
    {
        return firstPerson;
    }


    public void setFirstPerson(boolean firstPerson)
    {
        this.firstPerson=firstPerson;
        this.setEnabled(!this.isFirstPerson());
    }


    public float getRotZ()
    {
        return rotZ;
    }


    public void setRotZ(float rotZ)
    {
        this.rotZ=rotZ;
    }

    
   
    
	
	
}
